package cn.billy.org.service.impl;


import cn.billy.basic.utils.PageList;
import cn.billy.org.domain.Department;
import cn.billy.org.mapper.DepartmentMapper;
import cn.billy.org.query.DepartmentQuery;
import cn.billy.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
* @Description: IDepartmentService
* @Author: Billy
* @Version: 1.0
* @Date:  2022/6/21 21:21
*/
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {


    @Autowired
    private DepartmentMapper departmentMapper;

    /*
    * @Title: loadAll
    * @Description: 查询全部
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:22
    * @Parameters:
    * @Return
    */
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    /*
    * @Title: getById
    * @Description: 根据id查询
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:23
    * @Parameters:
    * @Return
    */
    @Override
    public Department getById(Long id) {
        return departmentMapper.getById(id);
    }

    /*
    * @Title: remove
    * @Description: 删除
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:23
    * @Parameters:
    * @Return
    */
    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    /*
    * @Title: save
    * @Description: 新增
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:23
    * @Parameters:
    * @Return
    */
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.add(department);
    }

    /*
    * @Title: update
    * @Description: 修改
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:23
    * @Parameters:
    * @Return
    */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /*
    * @Title: queryData
    * @Description: 分页+高级查询
    * @Author: Billy
    * @Version: 1.0
    * @Date:  2022/6/21 21:24
    * @Parameters:
    * @Return
    */
    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        Integer total = departmentMapper.queryCount(departmentQuery);
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        return new PageList<>(total,rows);
    }
}
